package com.kangyi.user.controller;

import com.kangyi.dto.HealthStatisticsQueryDTO;
import com.kangyi.result.Result;
import com.kangyi.user.service.HealthReportService;
import com.kangyi.vo.DynamicHealthStatisticsVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.List;

/**
 * @author Blank
 * @version 1.0
 */
@RestController
@RequestMapping("/user/report")
@Slf4j
@Api(tags = "健康数据统计相关接口")
public class HealthReportController {

    @Autowired
    private HealthReportService healthReportService;

    @GetMapping("/StatisticsOfBloodPressure")
    @ApiOperation("动态健康数据统计")
    public Result<DynamicHealthStatisticsVO> StatisticsOfBloodPressure(HealthStatisticsQueryDTO queryDTO) {
        log.info("动态健康数据统计: 开始日期 {}, 结束日期 {}, 客户ID {}, 查询字段 {}", queryDTO.getBegin(), queryDTO.getEnd(), queryDTO.getGuestId(), queryDTO.getFields());
        try {
            DynamicHealthStatisticsVO statisticsVO = healthReportService.getDynamicHealthStatistics(queryDTO.getBegin(), queryDTO.getEnd(), queryDTO.getGuestId(), queryDTO.getFields());
            return Result.success(statisticsVO, "查询成功");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }


    @GetMapping("/export")
    @ApiOperation("导出Excel报表接口")
    public Result export(HttpServletResponse response,@RequestParam Integer guestId){
        log.info("导出Excel报表接口：{}",guestId);
        try {
            healthReportService.getexport(response,guestId);
            return Result.success("导出成功！");
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

}
